package com.hualan.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.mapper.CharityCenterMapper;
import com.hualan.sfzy.model.dto.ArticleDto;
import com.hualan.sfzy.model.dto.CharityCenterDto;
import com.hualan.sfzy.model.entity.CharityCenter;
import com.hualan.sfzy.model.vo.ArticleQuery;
import com.hualan.sfzy.model.vo.CharityCenterQuery;
import com.hualan.sfzy.service.CharityCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 公益中心服务实现类
 */
@Service
public class CharityCenterServiceImpl implements CharityCenterService {
    @Autowired
    private CharityCenterMapper charityCenterMapper;

    @Override
    public int add(CharityCenter entity) {
        return charityCenterMapper.insert(entity);
    }

    @Override
    public int edit(CharityCenter entity) {
        return charityCenterMapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        return charityCenterMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return charityCenterMapper.deleteBatch(ids);
    }

    @Override
    public List<CharityCenter> find() {
        return charityCenterMapper.select(new CharityCenter());
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, CharityCenter entity) {
        throw new UnsupportedOperationException("此方法不支持，请使用findArticlePage");
    }
    @Override
    public  Map<String, Object> findCenterPage(Integer pageNum, Integer pageSize, CharityCenterQuery entity) {
        PageHelper.startPage(pageNum, pageSize);
        List<CharityCenterDto> list = charityCenterMapper.select(entity);
        PageInfo<CharityCenterDto> pageInfo = new PageInfo<>(list);
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put(CommonConstant.PAGE_LIST, list);
        pageMap.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        pageMap.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return pageMap;
    }

    @Override
    public CharityCenter findById(Integer id) {
        return charityCenterMapper.selectById(id);
    }
    
    @Override
    public List<CharityCenterDto> findAll() {
        return charityCenterMapper.selectAll();
    }
}